//我收藏的职位listview
import React, { Component } from 'react'
import {
    View,
    Text,
    Image,
    TouchableOpacity,
} from 'react-native';

import { collectStyle as styles } from '../../../../styles';
import sal from '../../../util/sal';

//加载action
import { DeleteCollectAction } from '../../../actions/postionAction';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import {common_url} from "../../../util/fetch";

var Dimensions = require('Dimensions');
var width = Dimensions.get('window').width;
var height = Dimensions.get('window').height;

class Collect_list extends Component {
    constructor(props) {
        super(props);
    };

    render() {
        return (
            <View style={styles.col_all}>
                <TouchableOpacity
                    activeOpacity={1}
                    onPress={() => { this.goGet('Postionin', this.props.postions.postionId); }}
                >
                    <View style={styles.col_top}>
                        <Text style={styles.col_pos}>{this.props.postion.postionName}</Text>
                        <Text style={styles.col_money}>{sal(this.props.postion.postionMm, this.props.postion.postionYm)}</Text>
                    </View>

                    <View style={styles.col_cen1}>
                        <Text style={styles.col_area}>{this.props.postion.postionSpace}</Text>
                        <Text style={styles.col_area}>{this.props.postion.postionExp}年经验</Text>
                        <Text style={styles.col_area}>{this.props.postion.postionEducation}</Text>
                    </View>

                    <View style={styles.col_cen2}>
                        <Image source={
                            this.props.company.companyPicture ?
                                {uri: common_url + "uploadImg/" + this.props.company.companyPicture}
                                :require('../../../img/app/company.png')} style={styles.head} />
                        <View style={styles.col_allin}>
                            <Text style={styles.col_com}>{this.props.company.companyName}</Text>
                            <View style={styles.col_texta}>
                                {this.fieldName(this.props.domains, 3)}
                            </View>
                        </View>
                    </View>
                </TouchableOpacity>

                <View style={styles.col_bot}>
                    <Text
                        style={[styles.col_no, { width: width * 0.45 }]}
                        onPress={() => {
                            actions.DeleteCollectAction({ postionId: this.props.postions.postionId });
                            this.props.deleteRow(this.props.postions.collectId);
                        }}
                    >
                        取消收藏
                        </Text>
                    <Text style={styles.col_line}></Text>
                    {this.props.postions.postionSend > 0 ?
                        <Text style={[styles.col_yes, { width: width * 0.45 }]}>已投递</Text>
                        :
                        <Text
                            style={[styles.col_yes, { width: width * 0.45 }]}
                            onPress={() => {
                                this.props.SendPostion_colAction.SendPostion_colAction({ postionId: this.props.postions.postionId });
                            }}
                        >
                            投递简历
                        </Text>
                    }
                </View>
            </View>
        )
    }

    fieldName(List, sl) {
        var data = {
            cont: List
        }
        var arr = [];
        var s = sl;
        var length = data.cont.length
        if (length <= s) {
            s = length
        }
        for (var i = 0; i < s; i++) {
            arr.push(
                <Text key={i} style={styles.col_txt}>{data.cont[i].field.fieldName}</Text>
            )
        }
        return arr;
    }

    goGet(name, id) {
        this.props.navigation.navigate(name, { useId: id });
    }
}

//组合action
var actions = {
    DeleteCollectAction,
}
//连接state到props
const mapStateToProps = state => {
    return {
        msg: state.DeleteCollectReducer,
    }
}
//连接action
const mapDispatchToProps = (dispatch) => {
    return {
        actions: bindActionCreators(actions, dispatch)
    }
}
//导出组合好的组件(组合后状态改变重新渲染组合组件的页面)
export default connect(
    mapStateToProps, mapDispatchToProps
)(Collect_list);